﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Project_01
{
    public partial class ConnectForm : Form
    {
        public ConnectForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String username = textBox1.Text;
            String password = textBox2.Text;
            if (username.Length > 0 && password.Length > 0 && username.Length < 36 && password.Length < 36) {
                try {
                    Database database = new Database(username, password);
                    Thread thread = new Thread(database.Connect);
                    thread.IsBackground = true;
                    thread.Start();
                } catch(Exception exception) {
                    MessageBox.Show("An error occured:\n" + exception.Message);
                }
            } else
                MessageBox.Show("The username and the password length\nmust be between 0 and 36 characters!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
}
